<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
document.title = "桃丽丝研究所 - 模型中心 - 日志管理"
const log = ref([])
const totalLog = ref(log.value.length);
// 当前页码，默认为第一页
const currentPage = ref(1);
// 每页显示的条数，默认10
const pageSize = ref(10);
const getLog = async () => {
  try {
    const res = await axios.get('/api/log/list',{
      params: {
        page: currentPage.value,
        pageSize: pageSize.value
      }
    })
    log.value = res.data.data
  }catch (e){
    ElMessage.error(`服务器错误!请与管理员联系！错误: ${e.message}`)
  }
}
// 页面分页改变时的处理函数
const handleCurrentChange = (newPage) => {
  currentPage.value = newPage;
  getLog()
};
onMounted(()=>{
  getLog()
})
</script>

<template>
<div class="log_container">
  <el-table :data="log">
    <el-table-column align="center" prop="MId" label="日志ID"></el-table-column>
    <el-table-column align="center" prop="MUser" label="下载用户"></el-table-column>
    <el-table-column align="center" prop="MName" label="下载模型名"></el-table-column>
    <el-table-column align="center" prop="MTime" label="下载时间"></el-table-column>
  </el-table>
  <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :background="true"
      :page-sizes="[10, 20, 50, 100]"
      :total="totalLog"
      layout="total, sizes, prev, pager, next, jumper"
      @current-change="handleCurrentChange"
  />
</div>
</template>

<style scoped>
.el-col{
  margin-bottom: 10px;
}
.el-table th, .el-table td {
  text-align: center !important;
}
</style>